package company;

class Test {
    public static void main(String[] args) {
        // 创建公司
        Company company = new Company("科技公司");

        // 创建部门
        HRDept hrDept = new HRDept(1, "人力资源部", "A座");
        TechDept techDept = new TechDept(2, "技术部", "B座");

        // 将部门添加到公司
        company.addDept(hrDept);
        company.addDept(techDept);

        // 创建全职员工
        FullTimeEmployee fullTimeEmp1 = new FullTimeEmployee(101, "张三", "高级经理", 90000.0, hrDept, "医疗保险、退休计划");
        FullTimeEmployee fullTimeEmp2 = new FullTimeEmployee(102, "李四", "软件工程师", 85000.0, techDept, "医疗保险、股票期权");

        // 创建兼职员工
        PartTimeEmployee partTimeEmp1 = new PartTimeEmployee(201, "王五", "招聘专员", 40000.0, hrDept, 20);
        PartTimeEmployee partTimeEmp2 = new PartTimeEmployee(202, "赵六", "网页开发", 35000.0, techDept, 25);

        // 将员工添加到公司
        company.addEmployee(fullTimeEmp1);
        company.addEmployee(fullTimeEmp2);
        company.addEmployee(partTimeEmp1);
        company.addEmployee(partTimeEmp2);

        // 将员工添加到部门
        hrDept.addEmployee(fullTimeEmp1);
        hrDept.addEmployee(partTimeEmp1);
        techDept.addEmployee(fullTimeEmp2);
        techDept.addEmployee(partTimeEmp2);

        // 更新员工信息
        Employee updatedEmp = new Employee(101, "张三", "总监", 95000.0, hrDept);
        company.updateEmployee(updatedEmp);

        // 更改员工部门
        company.changeEmployeeDept(fullTimeEmp2, hrDept);

        // 打印公司信息
        System.out.println("公司名称： " + company.getCompanyName());
        System.out.println("部门：");
        for (Dept dept : company.getDepartments()) {
            System.out.println("部门编号： " + dept.getDeptId() + ", 部门名称： " + dept.getDeptName() + ", 位置： " + dept.getLocation());
            System.out.println("该部门员工：");
            for (Employee emp : dept.getEmployees()) {
                System.out.println("员工编号： " + emp.getEmpId() + ", 姓名： " + emp.getName() + ", 职位： " + emp.getPosition() + ", 薪资： " + emp.getSalary());
                if (emp instanceof FullTimeEmployee) {
                    System.out.println("福利： " + ((FullTimeEmployee) emp).getBenefits());
                } else if (emp instanceof PartTimeEmployee) {
                    System.out.println("每周工作小时数： " + ((PartTimeEmployee) emp).getHoursPerWeek());
                }
            }
            System.out.println();
        }
    }
}

// Employee 类
class Employee {
    int empId;
    String name;
    String position;
    double salary;
    Dept department;

    // 构造函数
    public Employee(int empId, String name, String position, double salary, Dept department) {
        this.empId = empId;
        this.name = name;
        this.position = position;
        this.salary = salary;
        this.department = department;
    }

    // Getter 和 Setter 方法
    public int getEmpId() {
        return empId;
    }

    public void setEmpId(int empId) {
        this.empId = empId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public Dept getDepartment() {
        return department;
    }

    public void setDepartment(Dept department) {
        this.department = department;
    }
}

// FullTimeEmployee 类继承自 Employee
class FullTimeEmployee extends Employee {
    String benefits;

    public FullTimeEmployee(int empId, String name, String position, double salary, Dept department, String benefits) {
        super(empId, name, position, salary, department);
        this.benefits = benefits;
    }

    public String getBenefits() {
        return benefits;
    }

    public void setBenefits(String benefits) {
        this.benefits = benefits;
    }
}

// PartTimeEmployee 类继承自 Employee
class PartTimeEmployee extends Employee {
    int hoursPerWeek;

    public PartTimeEmployee(int empId, String name, String position, double salary, Dept department, int hoursPerWeek) {
        super(empId, name, position, salary, department);
        this.hoursPerWeek = hoursPerWeek;
    }

    public int getHoursPerWeek() {
        return hoursPerWeek;
    }

    public void setHoursPerWeek(int hoursPerWeek) {
        this.hoursPerWeek = hoursPerWeek;
    }
}

// Dept 类
class Dept {
    int deptId;
    String deptName;
    String location;
    Employee[] employees;

    public Dept(int deptId, String deptName, String location) {
        this.deptId = deptId;
        this.deptName = deptName;
        this.location = location;
        this.employees = new Employee[0];
    }

    // Getter 和 Setter 方法
    public int getDeptId() {
        return deptId;
    }

    public void setDeptId(int deptId) {
        this.deptId = deptId;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public Employee[] getEmployees() {
        return employees;
    }

    public void setEmployees(Employee[] employees) {
        this.employees = employees;
    }

    // 添加员工
    public void addEmployee(Employee employee) {
        Employee[] newEmployees = new Employee[employees.length + 1];
        System.arraycopy(employees, 0, newEmployees, 0, employees.length);
        newEmployees[employees.length] = employee;
        employees = newEmployees;
    }

    // 更新员工
    public void updateEmployee(Employee newEmployee) {
        for (int i = 0; i < employees.length; i++) {
            if (employees[i].getEmpId() == newEmployee.getEmpId()) {
                employees[i] = newEmployee;
                break;
            }
        }
    }
}

// HRDept 类继承自 Dept
class HRDept extends Dept {
    public HRDept(int deptId, String deptName, String location) {
        super(deptId, deptName, location);
    }
}

// TechDept 类继承自 Dept
class TechDept extends Dept {
    public TechDept(int deptId, String deptName, String location) {
        super(deptId, deptName, location);
    }
}

// Company 类
class Company {
    String companyName;
    Dept[] departments;
    Employee[] employees;

    public Company(String companyName) {
        this.companyName = companyName;
        this.departments = new Dept[0];
        this.employees = new Employee[0];
    }

    // Getter 和 Setter 方法
    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public Dept[] getDepartments() {
        return departments;
    }

    public void setDepartments(Dept[] departments) {
        this.departments = departments;
    }

    public Employee[] getEmployees() {
        return employees;
    }

    public void setEmployees(Employee[] employees) {
        this.employees = employees;
    }

    // 添加部门
    public void addDept(Dept dept) {
        Dept[] newDepartments = new Dept[departments.length + 1];
        System.arraycopy(departments, 0, newDepartments, 0, departments.length);
        newDepartments[departments.length] = dept;
        departments = newDepartments;
    }

    // 添加员工
    public void addEmployee(Employee employee) {
        Employee[] newEmployees = new Employee[employees.length + 1];
        System.arraycopy(employees, 0, newEmployees, 0, employees.length);
        newEmployees[employees.length] = employee;
        employees = newEmployees;
    }

    // 更新员工
    public void updateEmployee(Employee newEmployee) {
        for (int i = 0; i < employees.length; i++) {
            if (employees[i].getEmpId() == newEmployee.getEmpId()) {
                employees[i] = newEmployee;
                break;
            }
        }
    }

    // 更改员工部门
    public void changeEmployeeDept(Employee employee, Dept newDept) {
        employee.setDepartment(newDept);
        newDept.addEmployee(employee);
    }
}
